package com.xhs.controller;

import com.alibaba.fastjson2.JSONObject;
import com.xhs.message.ReturnResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.task.TaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @desc: 测试接口
 * @projectName: spring-boot-demo
 * @author: xhs
 * @date: 2025-05-28 周三 10:13
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    @Qualifier("taskExecutor")
    private TaskExecutor taskExecutor;

    @GetMapping("/getName")
    public ReturnResult<Object> getName() {
        log.info("<--------- 测试接口 START --------->");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", "小明");
        jsonObject.put("age", 18);
        // 异步任务
        taskExecutor.execute(() -> {
            log.info("<--------- 测试接口 异步任务 START --------->");
            JSONObject json = new JSONObject();
            json.put("name", "小黄");
            log.info("<--------- 测试接口 异步任务 END --------->");
        });
        log.info("<--------- 测试接口 END --------->");
        return ReturnResult.success().setData(jsonObject);
    }
}
